package com.andbase.demo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.andbase.demo.R;
import com.andbase.demo.activity.MainActivity;
import com.andbase.demo.model.MenuItem;
import com.andbase.library.view.recycler.AbRecyclerViewAdapter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;

import java.util.List;


public class MenuRecyclerViewAdapter extends AbRecyclerViewAdapter {

    private Context context;
    private List<Object> itemList;
    private RequestManager glide;

    public MenuRecyclerViewAdapter(Context context, List<Object> items) {
        super(context,items);
        this.context = context;
        this.itemList = items;
        glide = Glide.with(context);
    }


    @Override
    public RecyclerView.ViewHolder onCreateRecyclerViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_list_menu,parent,false);
        return new RecyclerViewHolder(view);
    }

    @Override
    public void onBindRecyclerViewHolder(RecyclerView.ViewHolder holder, final int position) {
        RecyclerViewHolder recyclerViewHolder = (RecyclerViewHolder)holder;
        final MenuItem menuItem = (MenuItem)itemList.get(position);
        recyclerViewHolder.menuText.setText(menuItem.getName());
        recyclerViewHolder.menuSubText.setText(menuItem.getDescription());
        recyclerViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((MainActivity)context).onItemClickListener(menuItem);
            }
        });
    }


    public class RecyclerViewHolder extends RecyclerView.ViewHolder {

        public final TextView menuText;
        public final TextView menuSubText;
        public final View itemView;

        public RecyclerViewHolder(View view) {
            super(view);
            itemView = view;
            menuText = (TextView) view.findViewById(R.id.item_menu_text);
            menuSubText = (TextView) view.findViewById(R.id.item_menu_subtext);

        }
    }

}